package com.blog.boot.webapp.controller;

import com.blog.boot.api.common.RestMsg;
import com.blog.boot.api.index.service.TestService;
import com.blog.boot.custom.error.impl.CustomExcetiponImpl;
import com.blog.boot.webapp.controller.common.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
public class TestController extends BaseController {

    @Autowired
    TestService testService;

    /*@RequestMapping("/index")
    public RestMsg.RestModelAndView index(HttpServletRequest request) {
        System.out.println("进来了");
        System.out.println(testService.testService());
        request.setAttribute("beetldemo", "哈哈哈哈哈成功了");
        return restFactory.setModelAndView("/index.html");
    }*/

    @RequestMapping("/header/{name}")
    public RestMsg.RestModelAndView taest(HttpServletRequest request,@PathVariable("name") String name) {
        System.out.println("进来了");
        System.out.println(testService.testService(name));
        request.setAttribute("beetldemo", "哈哈哈哈哈成功了");
        return restFactory.setModelAndView("/index1.html");
    }
    @RequestMapping("/list")
    @ResponseBody
    public RestMsg list() {
        RestMsg msg = restFactory.getMsg();
        try {
            int i = 0;
            i = i/0;
        }catch (RuntimeException e){
            throw new CustomExcetiponImpl(e.getMessage());
        }
        return msg;
    }

}
